import request from '@/utils/request'

// 评论查询参数
export interface CommentQuery {
  pageNo: number
  pageSize: number
  sortBy?: string
  isAsc?: boolean
  endKey?: string
  startTimestamp?: number
  postId: string
  lastEndKey?: string
  endCommentId?: string
}

// 更多子评论查询参数
export interface MoreSubCommentPageQuery {
  pageNo: number
  pageSize: number
  sortBy?: string
  isAsc?: boolean
  endKey?: string
  startTimestamp?: number
  commentId: string
  postId: string
  endCommentId?: string
}

// 评论DTO
export interface CommentDto {
  lastId?: string
  postId: string
  lastCommentId?: string
  content: string
}

// 评论API
export const commentApi = {
  // 根据帖子查询评论
  getByPost: (params: CommentQuery) => {
    return request.post('/comment/queryByPost', params)
  },

  // 查询更多子评论
  getMoreSubComments: (params: MoreSubCommentPageQuery) => {
    return request.post('/comment/queryMoreSubcomment', params)
  },

  // 添加评论
  add: (params: CommentDto) => {
    return request.post('/comment/insert', params)
  },

  // 点赞评论
  like: (commentId: string) => {
    return request.post(`/comment/likeComment/${commentId}`)
  },

  // 取消点赞评论
  dislike: (commentId: string) => {
    return request.post(`/comment/dislikeComment/${commentId}`)
  },

  // 删除评论
  delete: (commentId: string) => {
    return request.post(`/comment/deleteComment/${commentId}`)
  }
}